﻿using System;
using System.Collections.Generic;
using MySql.Simple.Mapper.Structures;

namespace MySql.Simple.Mapper.Readers
{
    /// <summary>
    /// Executes a SQL query and returns a list of integers
    /// </summary>
    public class StringReader
    {
        /// <summary>
        /// Executes a SQL query and returns a list of integers
        /// </summary>
        /// <param name="sql">The SQL.</param>
        /// <param name="connection">The connection.</param>
        /// <returns></returns>
        public static IList<string> Read(string sql, Connection connection)
        {
            var results = new List<string>();

            using (var dbConnection = connection.Open())
            {
                using (var command = dbConnection.CreateCommand())
                {
                    command.CommandText = sql;

                    using (var reader = command.ExecuteReader())
                    {
                        while(reader.Read())
                        {
                            results.Add(Convert.ToString(reader[0]));
                        }
                    }
                }
            }

            return results;
        }       
    }
}